package org.come.Frame;

import com.tool.tcpimg.UIUtils;
import org.come.Jpanel.TtJpanel;
import org.come.until.FormsManagement;
import org.come.until.MessagrFlagUntil;
import org.come.until.Music;

import javax.swing.*;
import javax.swing.plaf.basic.BasicInternalFrameUI;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;


public class TtJFrame
        extends JInternalFrame
        implements MouseListener {
    private TtJpanel ttJpanel;
    private int first_x;
    private int first_y;

    public static TtJFrame getTtJFrame() {
        return (TtJFrame) FormsManagement.getInternalForm(2230).getFrame();
    }


    public TtJFrame() {
        this.ttJpanel = new TtJpanel();
        add((Component) this.ttJpanel);

        setBorder(BorderFactory.createEmptyBorder());
        ((BasicInternalFrameUI) getUI()).setNorthPane(null);

        setBounds(210, 170, 674, 449);
        setOpaque(false);
        pack();
        setBackground(UIUtils.Color_BACK);
        setVisible(false);
        setDefaultCloseOperation(3);

        addMouseListener(this);
        addMouseMotionListener(new MouseMotionListener() {
            @Override
            public void mouseMoved(MouseEvent e) {
                if (MessagrFlagUntil.ImgFlagImg.equals(MessagrFlagUntil.MOUSE13)) {
                    MessagrFlagUntil.setMouse(MessagrFlagUntil.MOUSE1);
                }
            }


            @Override
            public void mouseDragged(MouseEvent e) {
                if (TtJFrame.this.isVisible()) {
                    int x = e.getX() - TtJFrame.this.first_x;
                    int y = e.getY() - TtJFrame.this.first_y;
                    TtJFrame.this.setBounds(x + TtJFrame.this.getX(), y + TtJFrame.this.getY(), TtJFrame.this.getWidth(), TtJFrame.this.getHeight());
                }
            }
        });
    }


    @Override
    public void mouseClicked(MouseEvent e) {
    }


    @Override
    public void mousePressed(MouseEvent e) {
        Music.addyinxiao("关闭窗口.mp3");

        if (e.isMetaDown()) {
            FormsManagement.HideForm(2230);
        } else {
            FormsManagement.Switchinglevel(2230);
        }
        this.first_x = e.getX();
        this.first_y = e.getY();
    }


    @Override
    public void mouseReleased(MouseEvent e) {
    }


    @Override
    public void mouseEntered(MouseEvent e) {
    }


    @Override
    public void mouseExited(MouseEvent e) {
    }


    public TtJpanel getTtJpanel() {
        return this.ttJpanel;
    }

    public void setTtJpanel(TtJpanel ttJpanel) {
        this.ttJpanel = ttJpanel;
    }
}


